package com.fieldchain.ex.fa100.utils.common;

import android.text.InputFilter;
import android.text.Spanned;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/10/29
 */
public class InputCount implements InputFilter {
    private int length = 4;

    public InputCount(int length) {
        this.length = length;
    }

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        if (dest.length() == 0 && source.equals(".")) {
            return "0.";
        }
        String dValue = dest.toString();
        String[] splitArray = dValue.split("\\.");
        if (splitArray.length > 1) {
            String dotValue = splitArray[1];
            if (dotValue.length() == length) {
                return "";
            }
        }
        return null;
    }
}
